package com.jfirer.validator.constraint.validator;

import java.math.BigDecimal;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import javax.validation.constraints.DecimalMax;

public class DecimalMaxValidator implements ConstraintValidator<DecimalMax, BigDecimal>
{
    private BigDecimal bigDecimal;
    
    @Override
    public void initialize(DecimalMax constraintAnnotation)
    {
        bigDecimal = BigDecimal.valueOf(Double.valueOf(constraintAnnotation.value()));
    }
    
    @Override
    public boolean isValid(BigDecimal value, ConstraintValidatorContext context)
    {
        if (value == null)
        {
            return true;
        }
        return bigDecimal.compareTo(value) >= 0;
    }
    
}
